package cn.wlj.origin.work;

import cn.wlj.origin.ConnectUtil;
import cn.wlj.origin.Constant;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

/**
 * @ClassName Sender
 * @Description TODO
 * @Author WLJ
 * @Date 2024/1/11 20:16
 * @Version 1.0
 */
public class Sender {
    public static void main(String[] args) throws Exception{
        // 队列名
        String queueName = Constant.Work.QUEUE_NAME;

        // 获取连接
        Connection connection = ConnectUtil.getConnection();
        // 获取通道
        Channel channel = connection.createChannel();
        // 声明队列
        channel.queueDeclare(queueName, false, false, true, null);
        String message = "work message";
        for (int i = 1; i <= 50; i++) {
            String msg = message + i;
            System.out.println("工作模式发送消息：" + msg);
            channel.basicPublish("", queueName, null, msg.getBytes());
            Thread.sleep(1000);
        }
        connection.close();
    }
}
